package com.ccc.boot.system.controller;

import com.ccc.boot.base.BaseController;
import com.ccc.boot.constant.CommonConstant;
import com.ccc.boot.pojo.DeptTree;
import com.ccc.boot.response.ResponseResult;
import com.ccc.boot.system.pojo.SysDeptTree;
import com.ccc.boot.system.entity.SysDept;
import com.ccc.boot.system.service.SysDeptService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 〈部门——REST接口〉
 *
 * @author superC
 * @date 2022/3/29
 * @version 0.1.0
 */
@RestController
@RequestMapping(CommonConstant.SYS_URI_PREFIX + "/dept")
public class SysDeptController extends BaseController<SysDept, SysDeptService> {

    @Resource
    private SysDeptService sysDeptService;

    @GetMapping("/getList/{deptName}")
    public ResponseResult getList(@PathVariable String deptName){
        SysDept sysDept = sysDeptService.getList(deptName);
        return ResponseResult.success("查询成功",sysDept);
    }

    /**
     * 获取部门tree（部门管理）
     *
     * @return {@link ResponseResult}
     * @date 2022/3/30 16:19
     * @author superC
     */
    @GetMapping("/getSysDeptTree")
    public ResponseResult getSysDeptTree() {
        List<SysDeptTree> tree = sysDeptService.getSysDeptTree();
        return ResponseResult.success("获取部门数据成功", tree);
    }

    /**
     * 获取部门tree（选择部门下拉框）
     *
     * @return {@link ResponseResult}
     * @date 2022/3/30 16:19
     * @author superC
     */
    @GetMapping("/getDeptTree")
    public ResponseResult getDeptTree() {
        List<DeptTree> tree = sysDeptService.getDeptTree();
        return ResponseResult.success("获取部门数据成功", tree);
    }

}
